import {call, put, takeLatest} from 'redux-saga/effects';
import {fromJS} from 'immutable';
import axios from 'axios';
import * as actionTypes from './actionTypes';

// 获取列表数据
function* getListData ():object{
    return yield axios.get('/api/headerList.json');
}

// 监听接口请求是否成功
function* getList():any{
    try {
        const result = yield call(getListData);
        yield put({
            type: actionTypes.GETLIST_SUCCESS,
            data: fromJS(result.data.data),
            totalPage: Math.ceil(result.data.data.length/10)
        })
    }
    catch (e) {
        console.log('error');
        // yield put({ type: "USER_FETCH_FAILED", message: e.message });
    }
}

export default function* saga() {
    yield takeLatest(actionTypes.GETLIST, getList);
}